package com.shawn.springboot.integeration.common.model;

import com.shawn.springboot.integeration.common.enums.ResponseCode;
import lombok.Getter;

/**
 * @author shawn
 * @description: 自定义返回类型
 * @date 2023/11/26
 */
@Getter
public class GenericResponse<T>{
    private int code;
    private String message;
    private T data;
    public GenericResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public GenericResponse(ResponseCode responseCode, T data) {
       this(responseCode.getCode(),responseCode.getMessage(),data);
    }
    public static GenericResponse error(String msg) {
        return new GenericResponse(ResponseCode.INTERNAL_ERROR.getCode(),msg,null);
    }
    public static GenericResponse success(Object data) {
        return new GenericResponse(ResponseCode.SUCCESS,data);
    }
}
